<template>
    <div>
        <el-row>
            <el-col :span="21"><el-input v-model="input" placeholder="请输入新任务" @keydown.enter="add()"/></el-col>
            <el-col :span="3"><el-button type="success" round @click="add()">添加任务</el-button></el-col>
        </el-row>
    </div>
</template>

<script>
export default {
    data() {
        return {
            input:''
        }
    },
    methods:{
        add(){
            //把文本框中的数据传递给父组件
            //如果this.input是空的。则显示输入，否则执行下面代码
            if(this.input == ''){
                alert('请输入代办事项！')
            }
            else{
                this.$emit('add',this.input)
                this.input = ''
            }
        }
    }
}
</script>